package com.aat.dxfy.buddy.test03;

import net.bytebuddy.ByteBuddy;
import net.bytebuddy.implementation.FixedValue;
import net.bytebuddy.matcher.ElementMatchers;

public class Test04 {

	public static void main(String[] args) {
		new Test04().test();
	}

	public void test() {
		try {
			Foo foo = new ByteBuddy().subclass(Foo.class)
					.method(ElementMatchers.isDeclaredBy(Foo.class))
					.intercept(FixedValue.value("One!"))
					.method(ElementMatchers.named("foo"))
					.intercept(FixedValue.value("Two!"))
					.method(ElementMatchers.named("foo").and(ElementMatchers.takesArguments(1)))
					.intercept(FixedValue.value("Three!")).make()
					.load(getClass().getClassLoader()).getLoaded().newInstance();
			System.out.println(foo.bar());
			System.out.println(foo.foo());
			System.out.println(foo.foo(1));
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
	}

}
